﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

public partial class register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void cmdReg_Click(object sender, EventArgs e)
    {
        string account = txtAccount.Text.Trim().ToLower();
        string password = txtPassword.Text.Trim().ToLower();
        string code = txtCode.Text.Trim();

        if (Session["RandomCode"] != null && code.Equals(Session["RandomCode"].ToString().ToLower()))
        {
            Model.User user = new Model.User();
            user.UserName = account;
            user.UserPassword = password;
            user.UserType = 1;
            user.AddTime = System.DateTime.Now;
            user.IsPass = true;
            //判断账号是存在
            BLL.User bll = new BLL.User();
            if (bll.Exists(" UserName='" + account + "'"))
            {
                MessageBox.Show(this.Page, "此账户已经存在，请重新输入账户！");
            }
            else
            {
                if (new BLL.User().Add(user) > 0)
                {
                    MessageBox.ShowAndRedirect(this.Page, "注册成功，请登录！", "login.aspx");
                }
                else
                {
                    MessageBox.Show(this.Page, "注册失败，请稍后重试！");
                }
            }
        }
        else
        {
            MessageBox.Show(this.Page, "验证码错误！");
        }



    }
}